package com.uinnova.springboot.initdata;

import com.uinnova.springboot.mongodb.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Configuration
public class InitBean {

    @Autowired
    User user;

    @Bean
    public User getInitData(){
        User user = new User("1","wanggang","1");
        System.out.println("构造函数执行完毕");
        return user;
    }

    /**
     *初始化之后执行(构造函数执行之后
     */
    @PostConstruct
    public void  initUser(){
        System.out.println("initBean-syso");
        System.out.println("我初始化好了");
        System.out.println(user);
    }

    @PreDestroy
    public void destroyUser(){
        System.out.println("user销毁");
    }
}
